package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.dto.req.SysNoticeDto;
import com.ruoyi.system.dto.resq.SysNoticeRespDto;
import com.ruoyi.system.service.SysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告信息Controller
 *
 * @author SUNLIANG
 */
@RestController
@RequestMapping("/notice")
public class SysNoticeController extends BaseController {
    @Autowired
    private SysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
//    @RequiresPermissions("system:notice:list")
    @GetMapping("/list")
    public TableDataInfo list(String noticeTitle) {
        startPage();
        List<SysNoticeRespDto> list = noticeService.selectNoticeList(noticeTitle);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
//    @RequiresPermissions("system:notice:query")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable String noticeId) {
        return AjaxResult.success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
//    @RequiresPermissions("system:notice:add")
//    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysNoticeDto sysNoticeDto) {
        return noticeService.insertNotice(sysNoticeDto);
    }

    /**
     * 修改通知公告
     */
//    @RequiresPermissions("system:notice:edit")
//    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysNoticeDto sysNoticeDto) {
        return noticeService.updateNotice(sysNoticeDto);
    }

    /**
     * 删除通知公告
     */
//    @RequiresPermissions("system:notice:remove")
//    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable List<String> noticeIds) {
        return noticeService.deleteNoticeByIds(noticeIds);
    }
}
